<template>
	<!-- 校友通讯录 -->
	<g-page :is-tabbar="false">
		<view class="content">
			<!-- 搜索 -->
			<view class="search">
				<!-- 搜索框参数：https://uviewui.com/components/search.html -->
				<u-search shape="round"  placeholder="输入姓名"></u-search>
			</view>
			<view class="item-box" v-for="(item,index) in mailList" :key="index">
				<view class="item-item">
					<view class="item-left">
						<view class="item-icon">
							<u-icon size="50" style="margin-left: 17rpx;height: 80rpx;line-height: 80rpx;"
								name="account-fill" color="#ffffff" />
						</view>
						<view class="item-left-t">
							<view class="item-left-t-name">
								{{item.name}}
							</view>
							<view class="item-left-t-dep" v-if="item.work_unit !== null">
								{{item.work_unit}}
							</view>
							<view class="item-left-t-dep" v-else-if="item.remark !== null">
								{{item.remark}}
							</view>
							<view class="item-left-t-dep" v-else>
								暂无工作信息
							</view>
						</view>
					</view>
					<view class="item-right" @tap="call(item.phone)">
						<u-icon size="35" name="phone-fill" style="margin-right: 20rpx;" color="red" />
					</view>
				</view>
				<u-line class="u-line" :hair-line="false"></u-line>
			</view>
		</view>
	</g-page>
</template>

<script>
	import {
		getContacts
	} from "@api"
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				page: 0,
				size: 100,
				mailList: [{
						name: '严晓波',
						work_unit: '工程实训中心',
						phone: '18278871121'
					}
				],
				userInfo:{}
			};
		},
		onLoad() {
			this.userInfo = this.USER.userInfo;
			this.getContactsList()
		},		
		computed: {
			...mapState(['USER'])
		},
		methods:{
			/* 获取数据 */
			getContactsList(){
				let userId = this.userInfo.id;
				getContacts({
					page: this.page,
					size: this.size,
					myId: userId
				}).then(res=>{
					this.mailList = res;
				}).catch(res=>{
					console.log("请求失败：",res)
				})
			},
			
			/* 打电话 */
			call(phoneNumber){
				uni.showToast({
					title:'拨打电话：'+phoneNumber,
					icon:'none'
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 10rpx 20rpx;
	}

	.search {
		margin-bottom: 20rpx;
	}

	.item {
		&-item {
			height: 120rpx;
			line-height: 120rpx;
			padding: 2rpx 20rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
		}

		&-left {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			height: 80rpx;
			line-height: 80rpx;

			&-t {
				display: flex;
				flex-direction: column;
				margin-left: 30rpx;
				margin-top: 20rpx;

				&-name,
				&-dep {
					height: 40rpx;
					line-height: 40rpx;
				}

				&-name {
					font-size: 1.1em;
				}

				&-dep {
					font-size: 24rpx;
					color: #96969a;
				}
			}
		}

		&-box {
			&:hover {
				background: #F6F6F6 !important;
			}
		}

		&-icon {
			width: 80rpx;
			height: 80rpx;
			margin-top: 20rpx;
			border-radius: 50%;
			background-color: #ff0000;
		}

		&-right {
			height: 120rpx;
			line-height: 120rpx;
		}
	}
</style>
